package com.example.exam.controller;

import com.example.exam.pojo.DTO.ExamPaperAnswerDTO.ExamPaperSubmitItemDTO;
import com.example.exam.pojo.DTO.QuestionDTO.QuestionAnswerDTO;
import com.example.exam.pojo.DTO.QuestionDTO.QuestionEditDTO;
import com.example.exam.pojo.entity.TExamPaperQuestionCustomerAnswer;
import com.example.exam.service.ICustomerAnswerService;
import com.example.exam.service.IQuestionService;
import com.example.exam.service.impl.ExamPaperAnswerImpl;
import com.example.exam.tools.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "题目答案管理")
@RequestMapping("/api/student/question/answer")
@Slf4j
public class QuestionAnswerController {

    @Autowired
    private ICustomerAnswerService customerAnswerService;
    @Autowired
    private IQuestionService questionService;


    @ApiOperation("根据ID查询单个题目的答题情况")
    @PostMapping(value = "/select/{id}")
    public JsonResult<QuestionAnswerDTO> select(@PathVariable Integer id){
        log.debug("开始处理【根据ID查询单个题目的答题情况】的请求，id={}",id);
        QuestionAnswerDTO dto = new QuestionAnswerDTO();

        TExamPaperQuestionCustomerAnswer answer = customerAnswerService.selectById(id);
        log.debug("根据前端传入的id查询用户答案实体：answer={}",answer);

        ExamPaperSubmitItemDTO answerDTO= customerAnswerService.getCustomerAnswer(answer);
        log.debug("根据用户答案实体获取其中的答案项：answerDTO={}",answerDTO);

        QuestionEditDTO questionDTO = questionService.getQuestionEditDTO(answer.getQuestionId());
        log.debug("根据用户答案实体获得其中的题目项：questionDTO={}",questionDTO);

        //把题目项和答案项放进DTO，传给前端
        dto.setQuestionDTO(questionDTO);
        dto.setQuestionAnswerDTO(answerDTO);
        return JsonResult.ok(dto);
    }
}
